﻿using KKU.RBSFPP.Shared.DAC;
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KKU.RBSFPP.Shared.Engines
{
    public static class DACExtension
    {
        public static void Create(this IDataAccessLayer data)
        {
            data.CreateOn = DateTime.Now;
        }

        public static void Delete(this IDataAccessLayer data)
        {
            data.DeleteOn = DateTime.Now;
        }

        public static IEnumerable<T> Display<T>(this IEnumerable<T> data) where T : ITrackable
        {
            return data.Where(it => it.DeleteOn.HasValue == false);
        }
    }

    public interface IDataAccessLayer : ITrackable
    {
        int Id { get; set; }
    }

    public interface ITrackable
    {
        DateTime CreateOn { get; set; }
        DateTime? DeleteOn { get; set; }
    }
}
